﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using uk.org.aspellclark.todolistppc;

namespace SyncToolProgram
{
    public partial class Reports : Form
    {
        List<SyncTask> _tasks = new List<SyncTask>();
        DateTime _outstandingDate = DateTime.Now;
        public Reports(List<SyncTask> tasks)
        {
            _tasks = tasks;
            InitializeComponent();

            Analyse(_tasks);
        }

        private void Analyse(List<SyncTask> tasks)
        {
            float hours = 0;
            int count = 0;
            int completedCount = 0;
            int outstandingCount = 0;
            int unscheduledcount = 0;
            foreach (SyncTask syncTask in tasks)
            {
                count++;
                if(syncTask.Complete)
                {
                    completedCount++;
                }
                else
                {
                    hours += syncTask.HoursEst;
                    if (syncTask.DueDate != new DateTime())
                    {
                        if (syncTask.DueDate < _outstandingDate)
                        {
                            outstandingCount++;
                        }
                    }
                    if (syncTask.DueDate == new DateTime())
                    {
                        unscheduledcount++;
                    }
                }


            }
            lblHours.Text = hours.ToString();
            lblcount.Text = count.ToString();
            lblComplete.Text = completedCount.ToString();
            lblOutstandingCount.Text = outstandingCount.ToString();
            lblUnscheduled.Text = unscheduledcount.ToString();
            TimeSpan ts = _outstandingDate - DateTime.Now;
            if (hours < ts.Days * 8)
            {
                lblDeliverable.Text = "True";
            }
            else
            {
                lblDeliverable.Text = "False";
            }
        }

        private void Reports_Load(object sender, EventArgs e)
        {
            
        }

        private void DateTimePicker1ValueChanged(object sender, EventArgs e)
        {
            _outstandingDate = dateTimePicker1.Value;
            Analyse(_tasks);
        }
    }
}
